package com.cx.base.day01_注解;

import lombok.extern.slf4j.Slf4j;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

@Slf4j
@AnnoForClassDemo(value = "classTest",strArr = {"test1","test2"})
public class AnnotationDemo {

    @AnnoForClassDemo(value = "methodTest",strArr = {"test1","test2"})
    public static void test(){
        System.out.println("test");
    }


    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        //从类上获取注解
        Class<AnnotationDemo> clazz = (Class<AnnotationDemo>) Class.forName("com.cx.base.day01_注解.AnnotationDemo");
        Annotation[] annotations = clazz.getAnnotations();
        AnnoForClassDemo annoInstance = (AnnoForClassDemo) annotations[0];
        log.debug("class annoInfo:{}",annoInstance.strArr());

        //从方法上获取注解
        Method method = clazz.getMethod("test");
        AnnoForClassDemo annoInstance2 = method.getAnnotation(AnnoForClassDemo.class);
        log.debug("method annoInfo:{}",annoInstance2.strArr());

    }
}
